package com.xujie.sportsmeeting.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 比赛成绩响应VO
 */
@Data
@Schema(description = "比赛成绩响应信息")
public class CompetitionScoreVO {

    @Schema(description = "成绩ID")
    private Long id;

    @Schema(description = "项目ID")
    private Long eventId;

    @Schema(description = "项目名称")
    private String eventName;

    @Schema(description = "项目编码")
    private String eventCode;

    @Schema(description = "运动员ID")
    private Long athleteId;

    @Schema(description = "运动员姓名")
    private String athleteName;

    @Schema(description = "学号")
    private String studentNumber;

    @Schema(description = "所属院系")
    private String department;

    @Schema(description = "所属班级")
    private String className;

    @Schema(description = "报名ID")
    private Long registrationId;

    @Schema(description = "成绩值")
    private String scoreValue;

    @Schema(description = "格式化后的成绩值")
    private String formattedScoreValue;

    @Schema(description = "成绩类型")
    private String scoreType;

    @Schema(description = "成绩类型描述")
    private String scoreTypeText;

    @Schema(description = "排名")
    private Integer ranking;

    @Schema(description = "得分")
    private BigDecimal points;

    @Schema(description = "是否最终成绩")
    private Integer isFinal;

    @Schema(description = "成绩类别描述")
    private String finalText;

    @Schema(description = "记录时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime recordTime;

    @Schema(description = "记录员ID")
    private Long recorderId;

    @Schema(description = "记录员姓名")
    private String recorderName;

    @Schema(description = "裁判员ID")
    private Long judgeId;

    @Schema(description = "裁判员姓名")
    private String judgeName;

    @Schema(description = "备注")
    private String remarks;

    @Schema(description = "状态")
    private Integer status;

    @Schema(description = "状态描述")
    private String statusText;

    @Schema(description = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @Schema(description = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    // 获取成绩类型描述
    public String getScoreTypeText() {
        if (scoreType == null) return "";
        switch (scoreType.toLowerCase()) {
            case "time": return "时间";
            case "distance": return "距离";
            case "score": return "分数";
            default: return scoreType;
        }
    }

    // 获取成绩类别描述
    public String getFinalText() {
        if (isFinal == null) return "";
        return isFinal == 1 ? "决赛" : "预赛";
    }

    // 获取状态描述
    public String getStatusText() {
        if (status == null) return "";
        return status == 1 ? "有效" : "无效";
    }

    // 获取排名显示文本
    public String getRankingText() {
        if (ranking == null || ranking <= 0) return "";
        
        switch (ranking) {
            case 1: return "🥇 第一名";
            case 2: return "🥈 第二名";
            case 3: return "🥉 第三名";
            default: return "第" + ranking + "名";
        }
    }
}
